<?php namespace Common\Model;
use \Hdphp\Model\Model;
	class User extends Model
	{
		protected $table = "user";
		//自动验证
		protected $validata = array(
		array("username","require","用户名不能为空",3,3),
		array("username","num:5,20","请输入正确的用户名",3,3),
		array("password","require","密码不能为空",3,3),
		);
		
		public function login()
		{
			if(!$this->create()) return false;//执行自动验证
			$username = $_POST["username"];
			$password = md5($_POST["password"]);
			//p($password);
			$data = $this->where("username","=",$username)->first();
			//p($data);	
			if(!$data){
				//用户名不存在
				$this->error = "用户名不存在";
				return false;
			}
			if($data["password"]!=$password){
				//判断密码是否正确
				$this->error = "密码错误";
				return false;
			}
			//存session
			$_SESSION["uid"] = $data["uid"];
			$_SESSION["username"] = $data["username"];
			return true;
		}
	}
